home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / comms / other / getit / core / getit.rexx < prev    next >
OS/2 REXX Batch file  |  1999-06-14  |  25KB  |  820 lines

  1.  /* */
  2.  
  3. signal on halt
  4. signal on break_c
  5.  
  6. call start
  7. call setDefaultConfig("GLOBAL",1)
  8. call readArguments
  9. call getStrings
  10. call openGui
  11. call readConfig(global.config,"GLOBAL")
  12. add=(global.file="")
  13. if global.url="" then call getUrl
  14. else call parseUrl
  15. if add then
  16.     if global.file~="" & pathpart(global.file)="" then global.file=AddPart(global.saveDir,global.file)
  17. call setMainGadgets
  18. call copyConf("GLOBAL","GLOBAL.INUSE")
  19. call setConfGadgets
  20. call UnLockWindows("S")
  21. call handle
  22. exit
  23. /***************************************************************************/
  24. error: procedure expose global. sigl
  25. parse arg code
  26.     if RXWIZERR~="RXWIZERR" then string = GetRxWizString(1001)":" RXWIZERR || d2c(10)
  27.     else string=""
  28.     string= string || GetRxWizString(code) || d2c(10) || GetRxWizString(1002)":" SIGL-1
  29.     call EasyRequest(string,global.prg)
  30.     exit
  31. /**************************************************************************/
  32. start: procedure expose global.
  33.     l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  34.     if AddLibrary("rexxsupport.library","rxsocket.library","rxasl.library","rxwiz.library")~=0 then exit
  35.     global.program="GetIt"
  36.     res=0
  37.     do i=1 while 1
  38.         global.rexxPort=global.program"."i
  39.         if OpenPort(global.rexxPort) then do
  40.             res=1
  41.             leave
  42.         end
  43.     end
  44.     if ~res then exit
  45.     global.filevalid=0
  46.     global.ver="1.0"
  47.     global.Author = "<alfier@iol.it>"
  48.     global.prg=ProgramName("NOEXT")
  49.     global.cat=global.prg".catalog"
  50.     global.AppName=global.rexxPort
  51.     global.AppIconName=global.rexxPort
  52.     global.path=PathPart(ProgramName("FULL"))
  53.     global.surface=AddPart(global.path,global.prg".wizard")
  54.     global.catalog=global.prg".catalog"
  55.     global.config=AddPart(global.path,global.prg".conf")
  56.     global.ss=0
  57.     global.aw=0
  58.     global.ps=PortSignal(global.rexxPort)
  59.     global.working=0
  60.     global.fun=0
  61.     global.host=""
  62.     global.port=80
  63.     global.remotefile=""
  64.     global.file=""
  65.     global.url=""
  66.     global.invalidurl=0
  67.     global.referer=""
  68.     global.range=0
  69.     global.login=""
  70.     global.pass=""
  71.     global.total=1
  72.     global.current=0
  73.     global.ns=0
  74.     return
  75. /***************************************************************************/
  76. setDefaultConfig: procedure expose global.
  77. parse arg stem,first
  78.  
  79.     if first~=1 then do
  80.         call copyConf("GLOBAL",stem)
  81.         return
  82.     end
  83.     interpret stem".SAVEDIR=''"
  84.     interpret stem".PROXY=''"
  85.     interpret stem".PROXYPORT=8080"
  86.     interpret stem".REFERER=''"
  87.     interpret stem".RESUME=1"
  88.     interpret stem".USEPROXY=0"
  89.     interpret stem".WATCHCLIP=1"
  90.     interpret stem".NOCACHE=0"
  91.     interpret stem".IMS=0"
  92.     interpret stem".TIMEOUT=0"
  93.     return
  94. /***************************************************************************/
  95. readArguments: procedure expose global.
  96.     parm.0.value=""
  97.     parm.1.value=""
  98.     parm.2.value=""
  99.     if ~ReadArgs("FILE,URL,PUBSCREEN/K,NOGUI/S,START/S,CONF/K") then do
  100.         call PrintFault(IoErr(),global.prg)
  101.         exit
  102.     end
  103.     global.file=parm.0.value
  104.     global.url=parm.1.value
  105.     global.screen=parm.2.value
  106.     global.nogui=parm.3.flag
  107.     global.start=parm.4.flag
  108.     if parm.5.flag then global.config=parm.5.value
  109.     return
  110. /***************************************************************************/
  111. openAboutWin: procedure expose global.
  112.     abw.noautoopen=1
  113.     abw.id=4
  114.     abw.gads=20
  115.     res=OpenWindow("S","ABW")
  116.     if res~=0 then call error(res)
  117.     set.disabled=~exists("libs:openurl.library")
  118.     call SetWizAttrs("S","ABW","ABPAGE","SET")
  119.     return
  120. /***************************************************************************/
  121. closeMainWin: procedure expose global.
  122.     call CloseWindow("S","MW","ONLYWIN")
  123.     return
  124. /***************************************************************************/
  125. openAuthWin: procedure expose global.
  126.     call LockWindows("S")
  127.     aw.ID=3
  128.     aw.Gads=20
  129.     aw.noautoopen=1
  130.     aw.noautoclose=1
  131.     aw.iconified=0
  132.     aw.SCREENTOFRONT=1
  133.     res=OpenWindow("S","AW")
  134.     if res~=0 then call error(res)
  135.     set.text=global.remoteFile
  136.     call SetWizAttrs("S","AW","AFILE","SET")
  137.     set.text=global.realm
  138.     call SetWizAttrs("S","AW","AREALM","SET")
  139.     call ActivateGadget("S","AW","ALOGIN")
  140.     return
  141. /***************************************************************************/
  142. setMainGadgets: procedure expose global.
  143.     set.string=global.url
  144.     set.ntype=3
  145.     call SetWizAttrs("S","MW","URL","SET")
  146.     set.string=global.file
  147.     call SetWizAttrs("S","MW","FILE","SET")
  148.     drop set.
  149.     if global.working then set.page=1
  150.     else set.page=0
  151.     call SetWizAttrs("S","MW","URLPAGER","SET")
  152.     call SetWizAttrs("S","MW","STOPPAGER","SET")
  153.     drop set.
  154.     set.current=global.current
  155.     set.total=global.total
  156.     call SetWizAttrs("S","MW","CANCEL","SET")
  157.     call SetWizAttrs("S","MW","STATUS","SET")
  158.     drop set.
  159.     set.text=global.url
  160.     call SetWizAttrs("S","MW","URLA","SET")
  161.     set.text=global.file
  162.     call SetWizAttrs("S","MW","FILEA","SET")
  163.     return
  164. /***************************************************************************/
  165. setConfGadgets: procedure expose global.
  166.     set.string=global.inuse.proxy
  167.     call SetWizAttrs("S","CW","PROXY","SET")
  168.     set.string=global.inuse.referer
  169.     call SetWizAttrs("S","CW","REFERER","SET")
  170.     set.string=global.inuse.saveDir
  171.     call SetWizAttrs("S","CW","SAVEDIR","SET")
  172.     drop set.
  173.     set.integer=global.inuse.proxyport
  174.     call SetWizAttrs("S","CW","PROXYPORT","SET")
  175.     set.integer=global.inuse.timeout
  176.     call SetWizAttrs("S","CW","TIMEOUT","SET")
  177.     drop set.
  178.     set.checked=global.inuse.useproxy
  179.     call SetWizAttrs("S","CW","USEPROXY","SET")
  180.     set.checked=global.inuse.nocache
  181.     call SetWizAttrs("S","CW","NOCACHE","SET")
  182.     set.checked=global.inuse.ims
  183.     call SetWizAttrs("S","CW","IMS","SET")
  184.     set.checked=global.inuse.resume
  185.     call SetWizAttrs("S","CW","RESUME","SET")
  186.     set.checked=global.inuse.watchclip
  187.     call SetWizAttrs("S","CW","WATCHCLIP","SET")
  188.     return
  189. /***************************************************************************/
  190. handle: procedure expose global.
  191.     stop=0
  192.     ctrl_c=2**12
  193.     if global.start then call safeStart
  194.     global.signals=or(global.ss,global.ps,ctrl_c,global.ns)
  195.     do while ~stop
  196.         mask=Wait(global.signals)
  197.         if and(mask,ctrl_c)~=0 then call break_c
  198.         if and(mask,global.ss)~=0 then if handleObj("") then leave
  199.         if and(mask,global.ps)~=0 then call handlePort
  200.         if and(mask,global.ns)~=0 then call handleClip
  201.     end
  202.     call safeQuit(1)
  203.     return
  204. /**************************************************************************/
  205. handleObj: procedure expose global.
  206. parse arg o
  207.     handle.wait=0
  208.     if o~="" then res=HandleSurface("S","HANDLE",o)
  209.     else res=HandleSurface("S","HANDLE")
  210.     if res~=0 then call error(res)
  211.     do i=0 to handle.imsg-1
  212.         w=handle.i.window
  213.         select
  214.             when handle.i.class="CLOSEWINDOW" then do
  215.                 if w=="AW" then do
  216.                     call CloseWindow("S","W")
  217.                     call UnlockWindows("S","MW")
  218.                 end
  219.                 call CloseWindow("S",w,"ONLYWIN")
  220.             end
  221.             when handle.i.class="VANILLAKEY" then call GadgetKey("S",handle.i.window,handle.i.code,handle.i.qualifier)
  222.             when handle.i.class="MENUPICK" then
  223.                 select
  224.                     when handle.i.ObjectID="MGETANOTHER" then do
  225.                         od=pragma("D",global.path)
  226.                         cmd = "run <NIL: >NIL: rx GetIt.rexx"
  227.                         shell command cmd
  228.                         call pragma("D",od)
  229.                     end
  230.                     when handle.i.ObjectID="CMSAVE" then do
  231.                         call copyConf("GLOBAL.INUSE","GLOBAL")
  232.                         call saveConfig
  233.                         call setMainGadgets
  234.                         call CloseWindow("S",w,"ONLYWIN")
  235.                     end
  236.                     when handle.i.ObjectID="CMSAVEAS" then do
  237.                         d=reqF(global.config,1)
  238.                         if d~="" then do
  239.                             global.config=d
  240.                             call copyConf("GLOBAL.INUSE","GLOBAL")
  241.                             call saveConfig
  242.                             call setMainGadgets
  243.                             call CloseWindow("S",w,"ONLYWIN")
  244.                         end
  245.                     end
  246.                     when handle.i.ObjectID="CMOPEN" then do
  247.                         d=reqF(global.config)
  248.                         if d~="" then
  249.                             if readConfig(d,"GLOBAL.INUSE")=0 then call setConfGadgets
  250.                     end
  251.                     when handle.i.ObjectID="CMUSE" then do
  252.                         call copyConf("GLOBAL.INUSE","GLOBAL")
  253.                         call setMainGadgets
  254.                         call CloseWindow("S",w,"ONLYWIN")
  255.                         call status global.str.CONFMODIFIED
  256.                     end
  257.                     when handle.i.ObjectID="CMLAST" then
  258.                         if readConfig(global.config,"GLOBAL.INUSE")=0 then call setConfGadgets
  259.                     when handle.i.ObjectID="CMRESTORE" then do
  260.                         call copyConf("GLOBAL","GLOBAL.INUSE")
  261.                         call setConfGadgets
  262.                         call setMainGadgets
  263.                     end
  264.                     otherwise if handle.i.ObjectID~="" & handle.i.config~="" then interpret handle.i.config
  265.                 end
  266.             when handle.i.class="IDCMPUPDATE" then do
  267.                 select
  268.                     when handle.i.ObjectID="POPFILE" then do
  269.                         d=reqF(global.file)
  270.                         if d~="" then do
  271.                             global.file=d
  272.                             set.string=global.file
  273.                             call SetWizAttrs("S","MW","FILE","SET")
  274.                         end
  275.                     end
  276.                     when handle.i.ObjectID="URL" then do
  277.                         global.url=handle.i.string;
  278.                         call parseUrl
  279.                     end
  280.                     when handle.i.ObjectID="FILLFILE" then
  281.                         if global.file~="" then do
  282.                             call getUrl
  283.                             set.string=global.url
  284.                             call SetWizAttrs("S","MW","URL","SET")
  285.                             set.text=global.url
  286.                             call SetWizAttrs("S","MW","URLA","SET")
  287.                         end
  288.                     when handle.i.ObjectID="POPSAVEDIR" then do
  289.                         d=reqF(global.inuse.saveDir,0,1)
  290.                         if d~="" then do
  291.                             global.inuse.saveDir=d
  292.                             set.string=d
  293.                             call SetWizAttrs("S","CW","SAVEDIR","SET")
  294.                         end
  295.                     end
  296.                     when handle.i.ObjectID="CSAVE" then do
  297.                         call copyConf("GLOBAL.INUSE","GLOBAL")
  298.                         call saveConfig
  299.                         call CloseWindow("S",w,"ONLYWIN")
  300.                     end
  301.                     when handle.i.ObjectID="CUSE" then do
  302.                         call copyConf("GLOBAL.INUSE","GLOBAL")
  303.                         call CloseWindow("S",w,"ONLYWIN")
  304.                         call status global.str.CONFMODIFIED
  305.                     end
  306.                     otherwise if handle.i.ObjectID~="" & handle.i.config~="" then interpret handle.i.config
  307.                 end
  308.             end
  309.             otherwise nop
  310.         end
  311.     end
  312.     return 0
  313. /**************************************************************************/
  314. reqF: procedure expose global.
  315. parse arg f,sm,dm
  316.     call LockWindows("S")
  317.     f.DoSaveMode=sm==1
  318.     f.DrawersOnly=dm==1
  319.     f.window="S/MW"
  320.     f.Drawer=PathPart(f)
  321.     f.File=FilePart(f)
  322.     res=ReqFile("F")
  323.     call UnLockWindows("S")
  324.     if res=0 then
  325.         if dm=1 then return f.drawer
  326.         else
  327.             if f.file~="" then return addpart(f.drawer,f.file)
  328.     return ""
  329. /**************************************************************************/
  330. status: procedure expose global.
  331. parse arg msg
  332.     set.format=msg
  333.     call SetWizAttrs("S","MW","STATUS","SET")
  334.     return
  335. /**************************************************************************/
  336. checkFile: procedure expose global.
  337.     if global.file="" then do
  338.         call status global.str.NOFILE
  339.         return 0
  340.     end
  341.     s=statef(global.file)
  342.     if s="" then
  343.         if ioerr()=205 then do
  344.             global.range=0
  345.             return 1
  346.         end
  347.         else do
  348.             call status global.str.CANTFIND "'"global.file"'"
  349.             return 0
  350.         end
  351.     parse var s type size d d d d d comment
  352.     if type~="FILE" then do
  353.         call status "'"global.file"'" global.str.NOTVALIDFILE
  354.         return 0
  355.     end
  356.     global.range=size
  357.     return 1
  358. /**************************************************************************/
  359. getUrl: procedure expose global.
  360.     if global.file~="" then do
  361.         s=statef(global.file)
  362.         if s~="" then do
  363.             parse var s type size d d d d d comment
  364.             if type="FILE" & upper(left(comment,8))=" HTTP://" then do
  365.                 global.url=word(comment,1)
  366.                 global.referer=word(comment,2)
  367.                 global.inuse.referer=global.referer
  368.                 set.strin=global.referer
  369.                 call SetWizAttrs("S","CW","REFERER","SET")
  370.                 call parseUrl
  371.                 call status global.str.URLFROMFILE
  372.                 return 1
  373.             end
  374.         end
  375.         call status global.str.NTURLFROMFILE
  376.     end
  377.     return 0
  378. /**************************************************************************/
  379. parseUrlFun: procedure expose global.
  380. parse arg stem,u
  381.  
  382.     if u="" then return 0
  383.  
  384.     p=80
  385.     f=""
  386.     l=""
  387.     pw=""
  388.  
  389.     pr=match("#?://#?",u)
  390.     if pr then do
  391.         parse var u proto "://" u
  392.         if upper(left(proto,7))~="HTTP" then return 0
  393.     end
  394.  
  395.     call SetStem(stem,"URL",u)
  396.  
  397.     if match("#?:#?@#?",u) then do
  398.         parse var u l":"pw"@"u
  399.         if l="" | pw="" | u="" then return 0
  400.     end
  401.  
  402.     if match("#?/#?",u) then do
  403.         parse var u u "/" f
  404.     end
  405.     if f="" then f = "/"
  406.  
  407.     if match("#?:#?",u) then do
  408.         parse var u u ":" p
  409.         if ~DataType(p,"N") then return 0
  410.         if p<1 | p>65535 then return 0
  411.         pr=1
  412.     end
  413.  
  414.     if pr then if u="" then return 0
  415.  
  416.     interpret stem".HOST='"u"'"
  417.     interpret stem".PORT='"p"'"
  418.     interpret stem".REMOTEFILE='"f"'"
  419.     interpret stem".LOGIN='"l"'"
  420.     interpret stem".PASS='"pw"'"
  421.     return 1
  422. /**************************************************************************/
  423. parseUrl: procedure expose global.
  424.     if parseUrlFun("GLOBAL",global.url) then do
  425.         if global.remotefile~="/" then new=FilePart(global.remotefile)
  426.         else new=global.AppName
  427.         if new~=global.AppIconName then do
  428.             set.AppIconName=new
  429.             call SetSurfaceAttrs("S","SET")
  430.             global.AppIcoNname=new
  431.         end
  432.         if global.file="" then call parseFile
  433.         global.invalidurl=0
  434.     end
  435.     else do
  436.         call status global.str.INVALIDURL
  437.         global.invalidurl=1
  438.     end
  439.     return
  440. /**************************************************************************/
  441. parseFile: procedure expose global.
  442.     rf=filepart(global.remotefile)
  443.     if rf~="" then do
  444.         global.file=rf
  445.         set.string=rf
  446.         call SetWizAttrs("S","MW","FILE","SET")
  447.     end
  448.     return
  449. /**************************************************************************/
  450. resetGadgets: procedure expose global.
  451.     set.page=0
  452.     call SetWizAttrs("S","MW","URLPAGER","SET")
  453.     call SetWizAttrs("S","MW","STOPPAGER","SET")
  454.     return
  455. /**************************************************************************/
  456. startIt: procedure expose global.
  457.     global.working=1
  458.  
  459.     if global.url="" then do
  460.         call status global.str.NOURL
  461.         return 0
  462.     end
  463.  
  464.     if ~checkFile() then return 0
  465.  
  466.     if upper(left(global.url,7))~="HTTP://" then u="http://"global.url
  467.     else u=global.url
  468.  
  469.     lfile=global.file
  470.     if global.SaveDir~="" & PathPart(global.file)="" then lfile=AddPart(global.SaveDir,lfile)
  471.  
  472.     command="GetItFun.rexx" global.rexxPort u global.host global.remotefile lfile "HOSTPORT" global.port
  473.     if global.useproxy & global.proxy~="" then command=command "PROXY" global.proxy PROXYPORT global.proxyport
  474.     if global.resume & global.range>0 then command=command "RANGE" global.range
  475.     if global.login~="" & global.pass ~="" then command=command "LOGIN" global.login "PASS" global.pass
  476.     if global.nocache then command=command "NOCACHE"
  477.     if global.ims then command=command "IMS" '"'GMTInetFileDate()'"'
  478.     if global.timeout>0 then command=command "TIMEOUT" global.timeout
  479.     if global.referer~="" then command=command "REFERER" global.referer
  480.  
  481.     set.page=1
  482.     call SetWizAttrs("S","MW","URLPAGER","SET")
  483.     call SetWizAttrs("S","MW","STOPPAGER","SET")
  484.     drop set.
  485.     set.text=global.url
  486.     call SetWizAttrs("S","MW","URLA","SET")
  487.     set.text=global.file
  488.     call SetWizAttrs("S","MW","FILEA","SET")
  489.  
  490.     od=pragma("D",global.path)
  491.     call RxsCall(command,-1)
  492.     call pragma("D",od)
  493.     return 1
  494. /**************************************************************************/
  495. handlePort: procedure expose global.
  496.     res=1
  497.     r=0
  498.     pkt=GetPkt(global.rexxPort)
  499.     if pkt~=null() then do
  500.         comm=GetArg(pkt)
  501.         parse var comm comm arg
  502.         if comm="ASKOVER" then r = WizEasyRequest("S","MW",2)
  503.         call Reply(pkt,r)
  504.         if r=1 then return res
  505.         select
  506.             when upper(comm)="INFO" then call status arg
  507.             when upper(comm)="MACRO" then global.fun=arg
  508.             when upper(comm)="TOTAL" then do
  509.                 global.total=arg
  510.                 set.Total=arg
  511.                 call SetWizAttrs("S","MW","STATUS","SET")
  512.             end
  513.             when upper(comm)="CURRENT" then do
  514.                 global.current=arg
  515.                 set.current=arg
  516.                 call SetWizAttrs("S","MW","STATUS","SET")
  517.             end
  518.             when upper(comm)="ERR" | upper(comm)="END" then do
  519.                 if upper(comm)="ERR" then call status arg
  520.                 global.working=0
  521.                 call resetGadgets
  522.                 global.fun=0
  523.                 res=0
  524.             end
  525.             when upper(comm)="AUTH" then do
  526.                 parse var arg "Basic realm=" '"'global.realm'"'
  527.                 global.working=0
  528.                 call resetGadgets
  529.                 global.fun=0
  530.                 res=0
  531.                 call openAuthWin
  532.             end
  533.             when upper(comm)="MOVED" then do
  534.                 parse var arg nurl nhost .
  535.                 if nhost="" then do
  536.                     if left(nurl,1)="/" then
  537.                         global.url="http://"global.host":"global.port || nurl
  538.                     else global.url=nurl
  539.                 end
  540.                 else global.url=AddPart(nhost,nurl)
  541.                 call parseurl
  542.                 call status "Moved:" arg
  543.                 call delay 10
  544.                 global.working=0
  545.                 call resetGadgets
  546.                 global.fun=0
  547.                 res=0
  548.                 call safeStart
  549.             end
  550.             otherwise nop
  551.         end
  552.     end
  553.     return res
  554. /**************************************************************************/
  555. copyConf: procedure expose global.
  556. parse arg from,to
  557.     interpret to".SAVEDIR="from".SAVEDIR"
  558.     interpret to".PROXY="from".PROXY"
  559.     interpret to".PROXYPORT="from".PROXYPORT"
  560.     interpret to".REFERER="from".REFERER"
  561.     interpret to".RESUME="from".RESUME"
  562.     interpret to".USEPROXY="from".USEPROXY"
  563.     interpret to".WATCHCLIP="from".WATCHCLIP"
  564.     interpret to".NOCACHE="from".NOCACHE"
  565.     interpret to".IMS="from".IMS"
  566.     interpret to".TIMEOUT="from".TIMEOUT"
  567.     return
  568. /**************************************************************************/
  569. readConfig: procedure expose global.
  570. parse arg file,stem
  571.     lines=ParseConfig(file,"CONF")
  572.     if lines==-1 then do
  573.         call status global.str.CONFIGFILE "'"file"'" global.str.NTFOUND
  574.         return 1
  575.     end
  576.  
  577.     call setDefaultConfig("GLOBAL.LOCAL")
  578.  
  579.     err=0
  580.     do i=0 to lines-1 while err=0
  581.         opt=conf.i
  582.         arg=conf.i.value
  583.         argu=upper(arg)
  584.         select
  585.             when opt=="SAVEDIR" then
  586.                 if arg="" then err=5
  587.                 else global.local.savedir=arg
  588.             when opt=="PROXY" then
  589.                 if arg="" then err=5
  590.                 else global.local.proxy=arg
  591.             when opt=="PROXYPORT" then
  592.                 if arg="" then err=5
  593.                 else if ~DataType(arg,"N") then err=2
  594.                      else if arg<1 | arg>65535 then err=2
  595.                            else global.local.proxyport=arg
  596.             when opt=="TIMEOUT" then
  597.                 if arg="" then err=5
  598.                 else if ~DataType(arg,"N") then err=2
  599.                      else if arg<0 then err=2
  600.                            else global.local.timeout=arg
  601.             when opt=="RESUME" then global.local.resume=1
  602.             when opt=="USEPROXY" then global.local.useproxy=1
  603.             when opt=="WATCHCLIP" then global.local.watchclip=1
  604.             when opt=="NOCACHE" then global.local.nocache=1
  605.             when opt=="IFMODIFIED" then global.local.ims=1
  606.             otherwise err=3
  607.         end
  608.     end
  609.     i=i-1
  610.  
  611.     select
  612.         when err==0 then do
  613.             call copyConf("GLOBAL.LOCAL",stem)
  614.             call status global.str.CONFREAD
  615.         end
  616.         when err==1 then call status global.str.BADOPT "'"arg"'" global.str.INLINE conf.i.line
  617.         when err==2 then call status global.str.BADNUM "'"arg"'" global.str.INLINE conf.i.line
  618.         when err==3 then call status global.str.UNKNOWNOPT "'"opt"'" global.str.INLINE conf.i.line
  619.         when err==4 then call status global.str.BADARG "'"arg"'" global.str.INLINE conf.i.line
  620.         when err==5 then call status global.str.OPT "'"opt"'" global.str.NEEDARG global.str.INLINE conf.i.line
  621.         otherwise nop
  622.     end
  623.     drop global.local.
  624.     return err
  625. /***************************************************************************/
  626. saveConfig: procedure expose global.
  627.     call status global.str.SAVINGCONF
  628.     if ~Open("OUT",global.config,"W") then do
  629.         call status global.str.CANTWRITE "'"global.config"'"
  630.         return
  631.     end
  632.     string="## " global.program global.ver "configuration file" || "A"x || "##" || "A"x
  633.     if global.saveDir~="" then string=string||"SAVEDIR" global.savedir || "A"x
  634.     if global.proxy~="" then do
  635.         string=string||"PROXY" global.proxy || "A"x
  636.         string=string||"PROXYPORT" global.proxyport || "A"x
  637.     end
  638.     if global.timeout~=0 then string=string||"TIMEOUT" global.timeout || "A"x
  639.     if global.resume then string=string||"RESUME"|| "A"x
  640.  
  641.     if global.useproxy then string=string||"USEPROXY"|| "A"x
  642.     if global.watchclip then string=string||"WATCHCLIP"|| "A"x
  643.     if global.nocache then string=string||"NOCACHE"|| "A"x
  644.     if global.ims then string=string||"IFMODIFIED"|| "A"x
  645.     if Writech("OUT",string)~=length(string) then sta=global.str.CANTWRITE "'"global.config"'"
  646.     else sta=global.str.CONFSAVED
  647.     call close("OUT")
  648.     call status sta
  649.     return
  650. /**************************************************************************/
  651. safeQuit: procedure expose global.
  652. parse arg e
  653.     if global.working & global.fun~=0 then do
  654.         call LockWindows("S")
  655.         call Signal(global.fun,2**12)
  656.         go=1
  657.         do while go
  658.             go=handlePort()
  659.             if (go) then do
  660.                 call Wait(global.ps)
  661.             end
  662.         end
  663.         call UnlockWindows("S")
  664.     end
  665.     if e then exit
  666.     return
  667. /**************************************************************************/
  668. safeStart: procedure expose global.
  669.  
  670.     if ~IsLibOn("SOCKET") then do
  671.         call status global.str.NOTCP
  672.         return 0
  673.     end
  674.  
  675.     if global.invalidurl then do
  676.         call status global.str.INVALIDURL
  677.         return 0
  678.     end
  679.  
  680.     call LockWindows("S")
  681.     global.current=0
  682.     set.current=0
  683.     global.total=1
  684.     set.total=1
  685.     call SetWizAttrs("S","MW","CANCEL","SET")
  686.     call SetWizAttrs("S","MW","STATUS","SET")
  687.  
  688.     if ~startIt() then do
  689.         call UnlockWindows("S")
  690.         call resetgadgets
  691.         global.working=0
  692.         return
  693.     end
  694.     call Wait(global.ps)
  695.     call handlePort()
  696.     call UnlockWindows("S")
  697.     return
  698. /**************************************************************************/
  699. GMTInetFileDate: procedure expose global.
  700. parse arg file
  701.     call GetDate("NOW","GMT")
  702.     date="NOW"
  703.     if GetFileDate(global.file,"FD") then do
  704.         call date2gmt("FD")
  705.         if CompareDates("NOW","FD")<0 then date="FD"
  706.     end
  707.     d.0="Sun";d.1="Mon";d.2="Tue";d.3="Wed";d.4="Thu";d.5="Fri";d.6="Sat"
  708.     m.1="Jan";m.2="Feb";m.3="Mar";m.4="Apr";m.5="May";m.6="Jun";m.7="Jul";m.8="Aug";m.9="Sep";m.10="Oct";m.11="Nov";m.12="Dec"
  709.     date=formatdate(date,"%m %w %d %Y %H:%M:%S GMT")
  710.     parse var date i j rest
  711.     i=i%1
  712.     return d.j"," m.i || rest
  713. /**************************************************************************/
  714. openGui: procedure expose global.
  715.     s.pubscreen=global.screen
  716.     s.fallback=1
  717.     s.snapshot=1
  718.     s.catalog=global.catalog
  719.     s.AppName=global.rexxPort
  720.     s.AppIcon=AddPart(global.path,global.program)
  721.     global.AppIcoNname=global.AppIconName
  722.     s.CxTitle=global.program global.ver global.author
  723.     s.CxDescr=global.str.CXDESCR
  724.     s.MasterWin="MW"
  725.     s.AutoClose=1
  726.     s.Iconified=global.nogui
  727.     res=OpenSurface(global.surface,"S")
  728.     if res~=0 then call error(res)
  729.     global.ss=SurfaceSignal("S")
  730.     mw.ID=1
  731.     mw.Gads=30
  732.     mw.Iconified=global.nogui
  733.     res=OpenWindow("S","MW")
  734.     call LockWindows("S")
  735.     cw.ID=2
  736.     cw.Gads=70
  737.     cw.maxheight=0
  738.     cw.NoWindow=1
  739.     cw.Iconified=0
  740.     res=OpenWindow("S","CW")
  741.     if res~=0 then call error(res)
  742.     call copyConf("GLOBAL","GLOBAL.INUSE")
  743.     global.noti=StartNotify("CLIP")
  744.     global.ns=NotifySignal(global.noti)
  745.     return
  746. /***************************************************************************/
  747. halt:
  748.     call safeQuit(1)
  749.     exit
  750. break_c:
  751.     call safeQuit(1)
  752.     exit
  753. /**************************************************************************/
  754. handleclip: procedure expose global.
  755.     if ~global.watchclip then return
  756.     if ReadTextClip("C")~=0 then do
  757.         parse upper var c "HTTP://"u .
  758.         cu=upper(c)
  759.         p=pos("HTTP://",cu,1)
  760.         if p>0 then do
  761.             p=p-1
  762.             parse var c +p u d "A"x
  763.             if parseUrlFun("GLOBAL.FAKEURL",u) then do
  764.                 od=pragma("D",global.path)
  765.                 cmd = "run <NIL: >NIL: rx GetIt.rexx URL" global.fakeurl.url
  766.                 shell command cmd
  767.                 call pragma("D",od)
  768.             end
  769.         end
  770.     end
  771.     return
  772. /**************************************************************************/
  773. openConfWin: procedure expose global.
  774. parse arg p
  775.     call copyConf("GLOBAL","GLOBAL.INUSE")
  776.     pw.ID=2
  777.     pw.Gads=70
  778.     res=OpenWindow("S","PW")
  779.     if res~=0 then call error(res)
  780.     return
  781. /**************************************************************************/
  782. getStrings: procedure expose global.
  783.     catalog=OpenCatalog(global.cat,"english",0)
  784.     global.str.NOFILE=GetCatalogStr(catalog,1000,"No file specified")
  785.     global.str.CANTFIND=GetCatalogStr(catalog,1001,"Can't find")
  786.     global.str.NOTVALIDFILE=GetCatalogStr(catalog,1002,"is not a valid file name")
  787.     global.str.URLFROMFILE=GetCatalogStr(catalog,1003,"URL derived from file")
  788.     global.str.NTURLFROMFILE=GetCatalogStr(catalog,1004,"Can't derive URL from file")
  789.     global.str.NOURL=GetCatalogStr(catalog,1005,"No URL specified")
  790.     global.str.CONFIGFILE=GetCatalogStr(catalog,1006,"Config file")
  791.     global.str.NTFOUND=GetCatalogStr(catalog,1007,"not found")
  792.     global.str.INLINE=GetCatalogStr(catalog,1008,"in line")
  793.     global.str.BADOPT=GetCatalogStr(catalog,1009,"Bad option")
  794.     global.str.BADNUM=GetCatalogStr(catalog,1010,"Bad number")
  795.     global.str.UNKNOWNOPT=GetCatalogStr(catalog,1011,"Unknown option")
  796.     global.str.BADARG=GetCatalogStr(catalog,1012,"Bad argument")
  797.     global.str.OPT=GetCatalogStr(catalog,1013,"Option")
  798.     global.str.NEEDARG=GetCatalogStr(catalog,1014,"needs an argument")
  799.     global.str.NOTCP=GetCatalogStr(catalog,1015,"No TCP/IP stack is running")
  800.     global.str.CXDESCR=GetCatalogStr(catalog,1016,"ARexx http dowloader")
  801.     global.str.SAVINGCONF=GetCatalogStr(catalog,1017,"Saving configuration...")
  802.     global.str.CANTWRITE=GetCatalogStr(catalog,1018,"Can't write to")
  803.     global.str.CONFSAVED=GetCatalogStr(catalog,1019,"Configuration saved")
  804.     global.str.CONFREAD=GetCatalogStr(catalog,1020,"Configuration read")
  805.     global.str.CONFMODIFIED=GetCatalogStr(catalog,1021,"Configuration modified")
  806.     global.str.INVALIDURL=GetCatalogStr(catalog,1022,"invalid URL")
  807.     call CloseCatalog(catalog);
  808.     return
  809. /**************************************************************************/
  810. sameFile: procedure
  811. parse arg a,b
  812.     o=pragma("D",PathPart(a))
  813.     o=pragma("D",o)
  814.     a=AddPart(o,FilePart(a))
  815.     o=pragma("D",PathPart(b))
  816.     o=pragma("D",o)
  817.     b=AddPart(o,FilePart(b))
  818.     return upper(a)==upper(b)
  819. /**************************************************************************/
  820. /*$VER: GetIt.rexx 4.5 (17.5.99)*/